<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>共享store实例</title>
</head>

<body>
  <script src="../../node_modules/vue/dist/vue.js"></script>
  <div id="app">
    <counter></counter>
    <counter></counter>
    <counter></counter>
    <button @click="inc">increment</button>
  </div>
  <script>
    // store可以当做一个Vue实例
    const state = new Vue({
      data(){
        return {
          count: 0
        }
      },
      methods: {
        inc() {
          this.count++
        }
      }
    })
    const Counter = {
      render(h) {
        return h('div', state.count);
      }
    }
    new Vue({
      el: '#app',
      components: { Counter },
      methods: {
        inc() {
          state.inc()
        }
      }
    })
  </script>
</body>

</html>